import http from '../../apis/api.js';
import map from '../../utils/map.js';
import util from '../../utils/util.js';
const app = getApp();
let self;
Page({
  data: {
    ownNo:'',
    isShow: false,/**是否显示菜单 */
    storeList: [],
    pagination: {
      page: 1,
      limit: 6,
      more: 0
    },
    loading: false,
    imgUrls: [
      '/images/banner1.png'
    ]
  },
  //事件处理函数
  bindViewTap: function () {
  },
  onLoad: function (options) {
    self = this;
    self.data.ownNo = options.ownNo;
  },
  onShow() {
    self.data.storeList = [];
    self.data.pagination = {
      page: 1,
      limit: 6,
      more: 0
    }
    self.getList();
  },
  getList() {
    let data = {
      ownNo: self.data.ownNo,
      page: self.data.pagination.page,
      limit: self.data.pagination.limit
    }
    self.setData({
      'loading': true
    })
    http.mystoreList(data).then(res => {
      if (res.page) {
        res.page.records.forEach(el => {
          el.briefIntroFormat = util.formateContent(el.briefIntro, 44);
          el.storePics.forEach(item => {
            if (item.picType == '51000101') {
              el.thumbnail = item.inPath;
            }
          })
          self.data.storeList.push(el);
        })
        self.data.pagination.more = Number(res.page.current) * Number(res.page.size) < res.page.total ? 1 : 0;
        self.setData({
          'loading': false,
          'storeList': self.data.storeList,
          'pagination': self.data.pagination
        })
      }

    });
  },
  onReachBottom() {/**上拉触底时间 */
    if (self.data.pagination.more > 0) {
      self.data.pagination.page++;
      self.getList();
    }
  },
  tapMore(e) {/**点击顶部菜单更多 */
    self.data.isShow = self.data.isShow ? false : true;
    self.setData({
      'isShow': self.data.isShow
    })
  },
  handlNavigator(e) {
    let data = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/myStoreDetail/myStoreDetail?storeNo=${data.storeno}&ownNo=${self.data.ownNo}`,
    })
  },
  goBack() {
    wx.navigateBack()
  }
})
